<?php

namespace App\Kuafu\Customer\Service;

use App\Kuafu\Common\Service\CommonService;
use App\Kuafu\Customer\Enum\CustomerCodeEnum;
use App\Kuafu\Customer\Model\CustomerModel;
use App\Kuafu\Customer\Exceptions\CustomerException;
use App\Kuafu\Base\Service\BaseService;

class CustomerService extends BaseService
{
    public static function addCustomer(array $data)
    {
        $data = [
            'name'          => '',
            'mobile'        => $data['mobile'],
            'createdAt'     => time(),
            'lastLoginAt'   => time(),
            'loginTimes'    => 1,
            'lastLoginIpAt' => (int)ip2long(CommonService::getRealIp()),
        ];
        $s    = CustomerModel::addData($data);
        if (!$s) {
            throw new CustomerException(CustomerCodeEnum::ERR_CUSTOMER_DB_ADD);
        }
        return $s;
    }

    public static function getUserInfo($columnValue, $field)
    {
        return CustomerModel::getUserInfoByColumn($columnValue, $field);
    }

    public static function setCustomer($userId, $data)
    {
        $s = CustomerModel::setCustomer($userId, $data);
    }
}
